﻿using System.Collections.Generic;
using NHibernate.Criterion;
using NhJump.Persistence.Context;
using NhJump.Persistence.Model;
using NhJump.Persistence.Querying.Definition;
using NhJump.Persistence.Querying.Executable;

namespace NhJump.Persistence
{
    public interface IReadableRepository<TEntity, TIdentifier>
        where TEntity : IDomainEntity<TIdentifier>
    {
        IUnitOfWork UnitOfWork { get; }

        /// <summary>
        ///     Entity is retrievable by its db identifier
        /// </summary>
        IExecutableQuery<TEntity, TIdentifier> ById(TIdentifier id);

        /// <summary>
        /// Prepares executable query according to query definition
        /// </summary>
        /// <param name="queryDefinition"></param>
        /// <returns></returns>
        IExecutableQuery<TEntity, TIdentifier> PrepareQuery(IQueryDefinition<TEntity, TIdentifier> queryDefinition);

        /// <summary>
        /// Executes the queryOver object and returns a list of entities
        /// </summary>
        /// <param name="queryOver"></param>
        /// <returns></returns>
        IList<TEntity> Execute(QueryOver<TEntity, TEntity> queryOver);

        /// <summary>
        /// Gets all the entities from the repository
        /// </summary>
        /// <returns></returns>
        IList<TEntity> GetAll();

        /// <summary>
        /// Gets a single entity by its identifier
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        TEntity Get(TIdentifier id);
    }
}